<?php
namespace app\index\controller;

use think\Controller;
use think\Cookie;
use think\Db;

class Personal extends Controller{
    public function index(){
        if(Cookie::has("username")){
            $name=Cookie::get("username")." <a href='".url('Index/cancel')."'>注销</a>";
        }else{
            $name=' <a href="'.url('Index/login').'">登录&注册</a>';
        }
        $date=Db::table("park_user")->where("username",Cookie::get("username"))->select();

        return view("Personal/index",["bo"=>$date,"username"=>$name]);
    }
    public function user_add(){
        if(request()->isPost()){
            $a=$_POST['address_t'];
            $a= implode('-',$a);
            $data['address_t'] = $a;
            $date=[
                'username'=>$_POST["username"],
                'sex'=>$_POST["sex"],
                'phone'=>$_POST["phone"],
                'mail'=>$_POST["mail"],
                'city'=>$a,
            ];
            $data=Db::table("park_user")->where("username",Cookie::get("username"))->update($date);
            if($data){
                $this->success("添加成功","index","",1);
            }else{
                $this->error("添加失败","index");
            }
        }
    }

}
